import os

from io import BytesIO
os.environ["APPBUILDER_TOKEN"] = ""
import appbuilder

from PIL import Image
def shi_bie(url):

    texts = []
    for i in url:
        print(i)
        # 假设你的图片路径是 'path_to_your_local_image.png'
        image_path = i

        # 使用PIL打开本地图片
        image = Image.open(image_path)

        # 将图片转换为字节数据
        byte_arr = BytesIO()
        image.save(byte_arr, format='PNG')  # 如有必要，转换为PNG格式
        byte_arr = byte_arr.getvalue()
        # 构建输入信息
        inp = appbuilder.Message(content={"raw_image": byte_arr})
        # 运行手写体识别
        handwrite_ocr = appbuilder.HandwriteOCR()
        out = handwrite_ocr.run(inp)
        # 打印识别结果
        data = out.content
        texts = [content['text'] for content in data['contents'] if content['position']['height'] >= 30]

    return texts
if __name__ == '__main__':
    print(shi_bie(["2ef8d05144a16f36d7e7f36fd7f81c7.jpg"]))
